﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication1
{
	/// <summary>
	/// Interaction logic for FriendRequestControl.xaml
	/// </summary>
	public partial class FriendRequestControl : UserControl
	{
		string from_id;
		string from_name;

        public FormConfirm form = null;
		static FriendRequestControl choosen = null;

		private static DependencyProperty MyBackgroundColorProperty = DependencyProperty.Register(
            "BackgroundColor", typeof(string), typeof(FriendRequestControl));
		public string BackgroundColor
		{
			get
			{
                return (string)GetValue(MyBackgroundColorProperty);
			}
			set
			{
			    SetValue(MyBackgroundColorProperty, value);
			}
		}
		
		public FriendRequestControl(string _from_id, string _from_name)
		{
			from_id = _from_id;
			from_name = _from_name;
			this.InitializeComponent();
			// Chèn profile picture
			BitmapImage bm = new BitmapImage();
			bm.BeginInit();
			bm.UriSource = new Uri(string.Format("https://graph.facebook.com/{0}/picture?type={1}", from_id, "square"));
			bm.EndInit();
			profile_picture.Source = bm;
			// Chèn name
			name.Text = from_name;
		}
		public void HideCloseButton()
		{
			close_button.Visibility = Visibility.Hidden;
		}
		public void ShowCloseButton()
		{
			close_button.Visibility = Visibility.Visible;
		}
		private void confirm_button_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			// TODO: Add event handler implementation here.
			if ((choosen != this) && (choosen != null))
			{
				choosen.form.Close();
				choosen.HideCloseButton();
			}
			choosen = this;
			ShowCloseButton();
			if (form != null)
			{
				form.Close();
			}
			
            form = new FormConfirm(from_id);
			//WindowsCofirmRequest window = new WindowsCofirmRequest(from_id);
            form.Show();
            
		}

		private void close_button_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			// TODO: Add event handler implementation here.
			HideCloseButton();
			if (form != null)
			{
				form.Close();
			}
		}
	}
}